package com.gexin.model.notice;

import com.gexin.common.utils.SQLUtils;
import com.gexin.model.notice.base.BaseNoticeNews;
import com.jfinal.plugin.activerecord.Page;
import org.apache.commons.lang3.StringUtils;

import java.util.LinkedList;
import java.util.List;

/**
 * 业务名称:  t_notice_news(资讯表) 
 */
@SuppressWarnings("serial")
public class NoticeNews extends BaseNoticeNews<NoticeNews> {
	public static final NoticeNews dao = new NoticeNews();

	public Page<NoticeNews> query(int pageNumber,int pageSize,NoticeNews news){
		List<Object> list =new LinkedList<Object>();
		SQLUtils sql=new SQLUtils(" from t_notice_news n left join t_notice_type t on t.id =n.type_id where 1=1 ");
		if(news!=null){
			 if(news.getTypeId()!=null){
			 	sql.append(" and n.type_id = ? ");
			 	list.add(news.getTypeId());
			 }
			 if(!StringUtils.isEmpty(news.getTitle())){
			 	sql.append(" and n.title like ? ");
			 	list.add("%"+news.getTitle()+"%");
			 }
			 if(news.getState()!=null){
			 	sql.append(" and n.state = ? ");
			 	list.add(news.getState());
			 }
		}
		sql.append(" order by n.is_index desc,n.create_time desc ");
		return paginate(pageNumber,pageSize,"select n.*,t.type_name ",sql.toString(),list.toArray());
	}

	public List<NoticeNews> findByAll(){
		return dao.find("select n.*,t.type_name from t_notice_news n left join t_notice_type t on t.id =n.type_id where n.state=0  order by n.create_time desc ");
	}
}
